﻿Imports System.Data.SqlClient
Public Class incomstaterment
    Dim cmd As New SqlCommand
    Public Sub refreshdata()
        grdincom.Rows.Clear()
        cmd.Connection = cn
        cmd.CommandText = " SELECT * FROM tblorder where orderDate between  '" & startdate.Value & "' and '" & enddate.Value & "'"
        Dim rd = cmd.ExecuteReader
        While rd.Read = True
            grdincom.Rows.Add(rd(0), rd(1), rd(2), rd(3), rd(4))
        End While
        rd.Close()
    End Sub
    Private Sub incomstaterment_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        condb()
     
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        Try
            refreshdata()
            ' for total invoice............
            cmd.Connection = cn
            cmd.CommandText = "select count (*) from tblorder where orderDate between '" & startdate.Value & "' and  '" & enddate.Value & "'"
            Dim invoice = cmd.ExecuteScalar
            lbltotalinvoice.Text = invoice

            'for Total Amonut 
            cmd.Connection = cn
            cmd.CommandText = " select SUM (Totallpay) from tblorder where orderDate between '" & startdate.Value & "' and  '" & enddate.Value & "'"
            Dim totalamount = cmd.ExecuteScalar
            lbltotalamount.Text = totalamount
        Catch ex As Exception
            MessageBox.Show("this month you not have values", "income Statement info", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try
    End Sub

    Private Sub btndelet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndelet.Click
        If MessageBox.Show("Do you want to delete", "Delete confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then
            Exit Sub
        End If
        For Each row In grdincom.SelectedRows
            Dim id = row.Cells("ProCode").Value
            cmd.Connection = cn
            cmd.CommandText = "delete from tblorder where invoiceid='" & id & "'"
            cmd.ExecuteNonQuery()

        Next
        refreshdata()

    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        Dim frm As New incomeReport
        frm.ShowDialog()
    End Sub
End Class